import '../utils/date_utils.dart';
import 'paging_model.dart';
import 'result_model.dart';

///学校作息:查询:请求
class SchoolDailyScheduleQueryReq extends PagingQueryReq {
  final String schoolId, semesterId, title;
  final int segment, status;

  SchoolDailyScheduleQueryReq({
    required this.schoolId,
    required this.semesterId,
    required this.segment,
    required this.title,
    required this.status,
    super.index,
    super.size,
  });

  @override
  Map<String, dynamic> toMap() {
    final map = super.toMap();
    map['semesterId'] = semesterId;
    map['segment'] = segment;
    map['title'] = title;
    map['status'] = status;
    return map;
  }
}

///学校作息:查询:响应
class SchoolDailyScheduleQueryRes
    extends PagingQueryRes<SchoolDailyScheduleItemRes> {
  SchoolDailyScheduleQueryRes({
    required super.retCode,
    required super.retMessage,
    super.total,
    super.rows,
  });

  factory SchoolDailyScheduleQueryRes.fromModel(final ResultModelRes res) {
    final ret = PagingQueryRes.fromModel(
      res,
      (row) => SchoolDailyScheduleItemRes.fromMap(row),
    );
    return SchoolDailyScheduleQueryRes(
      retCode: ret.retCode,
      retMessage: ret.retMessage,
      total: ret.total,
      rows: ret.rows,
    );
  }
}

///学校作息:数据项:响应
class SchoolDailyScheduleItemRes {
  final String id, title, remark, semesterId, startTime, endTime;
  final int status, segment;
  final DateTime? createdAt;

  const SchoolDailyScheduleItemRes({
    required this.id,
    required this.title,
    required this.remark,
    required this.semesterId,
    required this.segment,
    required this.startTime,
    required this.endTime,
    required this.status,
    required this.createdAt,
  });

  factory SchoolDailyScheduleItemRes.fromMap(Map<String, dynamic> map) =>
      SchoolDailyScheduleItemRes(
        id: map['id'] ?? '',
        title: map['title'] ?? '',
        remark: map['remark'] ?? '',
        semesterId: map['semesterId'] ?? '',
        segment: map['segment'] ?? 0,
        startTime: map['startTime'] ?? '',
        endTime: map['endTime'] ?? '',
        status: map['status'] ?? 0,
        createdAt: dateUtils.parse('yyyy-MM-dd HH:mm:ss', map['createdAt']),
      );
}

///学校作息:加载:响应
class SchoolDailyScheduleInfoRes extends SchoolDailyScheduleItemRes
    with ModelRes {
  @override
  final int retCode;
  @override
  final String retMessage;

  SchoolDailyScheduleInfoRes({
    required this.retCode,
    required this.retMessage,
    required SchoolDailyScheduleItemRes item,
  }) : super(
          id: item.id,
          title: item.title,
          remark: item.remark,
          semesterId: item.semesterId,
          segment: item.segment,
          startTime: item.startTime,
          endTime: item.endTime,
          status: item.status,
          createdAt: item.createdAt,
        );

  factory SchoolDailyScheduleInfoRes.fromModel(final ResultModelRes res) =>
      SchoolDailyScheduleInfoRes(
        retCode: res.retCode,
        retMessage: res.retMessage,
        item: SchoolDailyScheduleItemRes.fromMap(res.toMap),
      );
}

///学校作息:新增:请求
class SchoolDailyScheduleAddReq {
  final String schoolId, title, remark, semesterId, startTime, endTime;
  final int segment;

  const SchoolDailyScheduleAddReq({
    required this.schoolId,
    required this.title,
    required this.remark,
    required this.semesterId,
    required this.segment,
    required this.startTime,
    required this.endTime,
  });

  Map<String, dynamic> toMap() => {
        'title': title,
        'remark': remark,
        'semesterId': semesterId,
        'segment': segment,
        'startTime': startTime,
        'endTime': endTime,
      };
}

///学校作息:修改:请求
class SchoolDailyScheduleModifyReq {
  final String id, title, remark, semesterId, startTime, endTime;
  final int segment, status;

  const SchoolDailyScheduleModifyReq({
    required this.id,
    required this.title,
    required this.remark,
    required this.semesterId,
    required this.segment,
    required this.startTime,
    required this.endTime,
    required this.status,
  });

  Map<String, dynamic> toMap() => {
        'title': title,
        'remark': remark,
        'semesterId': semesterId,
        'segment': segment,
        'startTime': startTime,
        'endTime': endTime,
        'status': status,
      };
}
